import axios from '../axios';
import exportURL from './exportURL';
import {get} from 'http';

const [
  v,
  group,
  materials,
  user,
  stock,
  norm,
  ugroup,
  permission,
  supplier,
  brand,
  skp,
  message,
  order,
  data
] = [
  'v1',
  'group',
  'materials',
  'user',
  'stock',
  'norm',
  'ugroup',
  'permission',
  'supplier',
  'brand',
  'skp',
  'message',
  'order',
  'data'
];
//  ***************************************************** data 数据中台
export const getDataCenter = () => axios({
  method: 'get',
  url: exportURL(`${v}/${data}/data`)
});
//  ----------------------------------------------------- data 数据中台
//  ***************************************************** Head 清除缓存
export const clearCache = () => axios({
  method: 'get',
  url: exportURL(`${v}/api/flush`)
});

// 获取待处理事件总数的数量
// https://store.fdimall.com/v1/message/agents
export const getSocketCount = () => axios({
  method: 'get',
  url: exportURL(`${v}/message/agents`)
});
//  ----------------------------------------------------- Head 清除缓存


//  ***************************************************** Login 登录获取token
export const getToken = (username, password) => axios({
  method: 'post',
  url: `${v}/${user}/login`,
  data: {
    username,
    password
  }
});
//  ----------------------------------------------------- Login 登录获取token

//  ***************************************************** 修改密碼
export const editPassword = (password, new_password) => axios({
  method: 'post',
  url: exportURL(`${v}/${user}/udp`),
  data: {
    password,
    new_password
  }
});
//  ----------------------------------------------------- 修改密碼


//  ***************************************************** 首页城市数据
// message/cityaccess
export const getCity = () => axios({
  method: 'get',
  url: exportURL(`${v}/${message}/cityaccess`)
});
//  ----------------------------------------------------- 首页城市数据

//  ***************************************************** 获取 U8token
export const getU8Token = () => axios({
  method: 'get',
  url: exportURL(`${v}/api/u8token`)
});
//  ----------------------------------------------------- 获取 U8token

//  *****************************************************MaterialGroup物料组库
// 数据初始化
export const getMaterialGroupData = () => axios({
  method: 'get',
  url: exportURL(`${v}/${group}`)
});
// 查看物料组信息
export const getMaterialGroupInfo = id => axios({
  method: 'get',
  url: exportURL(`${v}/${group}/${id}`)
});
// 增加新组
export const addMaterialGroup = data => axios({
  method: 'post',
  url: exportURL(`${v}/${group}`),
  data
});
// 修改数据
export const editMaterialGroup = (data = {}, pid) => axios({
  method: 'put',
  url: exportURL(`${v}/${group}/${pid}`),
  data
});
// 删除数据
export const delMaterialGroup = id => axios({
  method: 'delete',
  url: exportURL(`${v}/${group}/${id}`)
});
//  ----------------------------------------------------- MaterialGroup物料组库

//  ***************************************************** CodeLibrary 编码库
// 导入
// url: 'v1/detail/upload',
//   method: 'post',
//   data: formData,

export const myUpload = formData => axios({
  method: 'post',
  url: exportURL(`${v}/detail/upload`),
  data: formData
});


// 获取编码库左侧的导航的详细信息
export const getCodeLibraryInfo = (cate_code, page, page_size, search) => axios({
  method: 'get',
  url: exportURL(`${v}/${materials}`),
  params: {
    cate_code,
    page,
    page_size,
    search
  }
});
// 增加编码 物料
export const addCodeLibrary = data => axios({
  method: 'post',
  url: exportURL(`${v}/${materials}`),
  data
});
// 修改
export const editCodeLibrary = (invcode, data) => axios({
  method: 'put',
  url: exportURL(`${v}/${materials}/${invcode}`),
  data
});
// 删除
export const delCodeLibrary = invcode => axios({
  method: 'delete',
  url: exportURL(`${v}/${materials}/${invcode}`)
});
// 获取所有品牌
export const getAllBrand = () => axios({
  method: 'get',
  url: exportURL(`${v}/gbrand`)
});

// 品牌搜索select
// https://store.fdimall.com/v1/gbrand/search
export const getSearchBrand = search => axios({
  method: 'post',
  url: exportURL(`${v}/gbrand/search`),
  data: {
    search
  }
});

// 获取单个物料
// https://store.fdimall.com/v1/materials/0101030900001
// GET
// invcode	是	string	物料编码
export const getSingleCode = invcode => axios({
  method: 'get',
  url: exportURL(`${v}/${materials}/${invcode}`)
});


// 推送U8  post
// https://store.fdimall.com/v1/materials/postu8
export const pushU8 = invcode => axios({
  method: 'post',
  url: exportURL(`${v}/${materials}/postu8`),
  data: {
    invcode
  }
});

// 推送采购 post
// https://store.fdimall.com/v1/materials/postqipu
export const pushPurchase = invcode => axios({
  method: 'post',
  url: exportURL(`${v}/${materials}/postqipu`),
  data: {
    invcode
  }
});
//  ----- ------------------------------------------------ CodeLibrary 编码库

//  ***************************************************** goodsLibrary 商品库
// 获取 所有商品数据
export const getGoodsLibraryData = ({page = 1, page_size = 10}, params) => axios({
  method: 'get',
  url: exportURL(`${v}/${skp}/search`),
  params: {
    page,
    page_size,
    ...params
  }
});
// 删除商品数据
// https://store.fdimall.com/v1/skp/123
// DELETE
export const delGoodData = id => axios({
  method: 'delete',
  url: exportURL(`${v}/${skp}/${id}`)
});
// 搜索商品数据
// https://store.fdimall.com/v1/skp/search
// get
export const seachGoodsData = params => axios({
  method: 'get',
  url: exportURL(`${v}/${skp}/search`),
  params
});

// 上架/下架
// https://store.fdimall.com/v1/shelf/id(id==skp表id)
// PUT
// 参数名	必选	类型	说明
// is_line	是	string	0未上架1已下架
// qty	上架需要	string	现存量
export const onOrOffShelves = (id, params) => axios({
  method: 'put',
  url: exportURL(`${v}/shelf/${id}`),
  data: {
    ...params
  }
});

//  ----------------------------------------------------- goodsLibrary 商品库

// 导入
// url: 'v1/detail/goods',
//   method: 'post',
//   data: formData,

export const goodsLibraryUpload = formData => axios({
  method: 'post',
  url: exportURL(`${v}/detail/goods`),
  data: formData
});

//  ***************************************************** generatingGoods 生成商品
// 所有物料组一层级别传递级
// https://store.fdimall.com/v1/groupnotree
export const getGroupnoTree = (level = '') => axios({
  method: 'get',
  url: exportURL(`${v}/groupnotree${level}`)
});
// 获取所有供应商
// https://store.fdimall.com/v1/supplie
export const getSupplierData = () => axios({
  method: 'get',
  url: exportURL(`${v}/${supplier}`)
});
// 通过供应商获取物流模板
// https://www.store.com/v1/template
// POST
// user_id	是	string	供应商id
export const getLogisticsTemplate = user_id => axios({
  method: 'get',
  url: exportURL(`${v}/template/${user_id}`)
});

// 获取一条商品数据  通过修改获取生成商品页面
// https://store.fdimall.com/v1/skp
// GET
export const editGoodData = id => axios({
  method: 'get',
  url: exportURL(`${v}/${skp}`),
  params: {
    id
  }
});

// 规格改变 获取规格里面的数据
export const getSpecChangeData = code => axios({
  method: 'get',
  url: exportURL(`${v}/${norm}/${code}`)
});

// 增加 生产商品
// https://store.fdimall.com/v1/skp
export const addGoodsData = data => axios({
  method: 'post',
  url: exportURL(`${v}/${skp}`),
  data
});

// 更新商品数据
// https://store.fdimall.com/v1/skp/123
// PUT

export const updateGoodData = (data, code) => axios({
  method: 'put',
  url: exportURL(`${v}/${skp}/${code}`),
  data
});

//  ----------------------------------------------------- generatingGoods 生成商品


//  ***************************************************** specsLibrary 规格库
//上传规格
// url: 'v1/detail/spec',
//   method: 'post',
//   data: formData,

export const mySpecsUpload = formData => axios({
  method: 'post',
  url: exportURL(`${v}/detail/spec`),
  data: formData
});

// 获取 商品数据
export const getspecsLibraryData = code => axios({
  method: 'get',
  url: exportURL(`${v}/${norm}/${code}`)
});
// 添加规格组
// https://store.fdimall.com/v1/norm
export const addspecsLibraryData = (cate_code, name) => axios({
  method: 'post',
  url: exportURL(`${v}/${norm}`),
  data: {
    cate_code,
    name
  }
});

// 添加规格
// https://store.fdimall.com/v1/norm/add
// POST
// param	是	string	规格名称
// pid	是	string	规格组id
export const addspecs = (param, pid) => axios({
  method: 'post',
  url: exportURL(`${v}/${norm}/add`),
  data: {
    param,
    pid
  }
});

// 更新规格组/规格
// https://store.fdimall.com/v1/norm/9506
// PUT
export const editspecs = (name, code) => axios({
  method: 'put',
  url: exportURL(`${v}/${norm}/${code}`),
  data: {
    name
  }
});

// 删除规格组/规格
// https://store.fdimall.com/v1/norm/9506
export const delspecs = code => axios({
  method: 'delete',
  url: exportURL(`${v}/${norm}/${code}`)
});

//  ----------------------------------------------------- specsLibrary 规格库


//  ***************************************************** instructionLibrary 指令库

// 导入
// url: 'v1/detail/instruction',
//   method: 'post',
//   data: formData,

export const instructionLibraryUpload = formData => axios({
  method: 'post',
  url: exportURL(`${v}/detail/instruction`),
  data: formData
});


// 查看指令库
// http://store.fdimall.com/v1/message
// GET
// page_size	是	int	页数
// page	是	int	页号
// export const
export const getInstructionLibraryData = (page, page_size, search = '') => axios({
  method: 'get',
  url: exportURL(`${v}/${message}`),
  params: {
    page_size,
    page,
    search
  }
});

// 查看指令详情
// https://store.fdimall.com/v1/detail/code
// GET

export const getInstructionSingle = params => axios({
  method: 'get',
  url: exportURL(`${v}/detail/${params.id}`),
  params: {
    type: params.type
  }
});

// 驳回采购需求
// http://store.fdimall.com/v1/message/id
// PUT
export const rejectInstructionrequest = (id, msg) => axios({
  method: 'put',
  url: exportURL(`${v}/${message}/${id}`),
  data: {
    msg
  }
});

// 同意预采购需求 == 物料批量添加
//POST
// https://store.fdimall.com/v1/materials
export const agreeInstructionrequest = code => axios({
  method: 'post',
  url: exportURL(`${v}/${message}`),
  data: {
    code
  }
});

// 查询用户指令数
// https://store.fdimall.com/v1/message/mgcount
// GET params:{username:'ndsklad'}

export const getInstructionCount = username => axios({
  method: 'get',
  url: exportURL(`${v}/${message}/mgcount`),
  params: {
    username
  }
});

// 导出Excel
// https://store.fdimall.com/v1/detail/excel
export const exportExcel = (children, type) => axios({
  method: 'post',
  url: exportURL(`${v}/detail/excel`),
  data: {
    children,
    type
  }
});


//  ----------------------------------------------------- instructionLibrary 指令库


//  ***************************************************** userList 用户列表
// 添加用户
// https://store.fdimall.com/v1/user/add
// POST
// 参数名	必选	类型	说明
// password	是	string	密码
// user_group_id	是	int	用户组ID
// username	否	int	登录名
// mail	否	str	邮箱
// phone	否	str	电话

export const addUser = data => axios({
  method: 'post',
  url: exportURL(`${v}/${user}/add`),
  data
});


// 用户列表：
// https://store.fdimall.com/v1/user
// GET
// 参数名	必选	类型	说明
// id	否	int	用户id
export const getUserList = (page = 1, page_size = 10) => axios({
  method: 'get',
  url: exportURL(`${v}/${user}`),
  params: {
    page,
    page_size
  }
});

// 编辑用户
// https://store.fdimall.com/v1/user/edit
// POST
// user_group_id	是	int	用户组ID
// id	是	int	用户ID
// password	否	str	用户密码

export const editUser = data => axios({
  method: 'post',
  url: exportURL(`${v}/${user}/edit`),
  data
});


// https://store.fdimall.com/v1/user/60
// delete
export const delUser = id => axios({
  method: 'delete',
  url: exportURL(`${v}/${user}/${id}`)
});


//  ----------------------------------------------------- userList 用户列表


//  ***************************************************** roleList 角色列表

// 组列表
// https://store.fdimall.com/v1/ugroup/list
// GET
// 参数：
// 参数名	必选	类型	说明
// group_id	否	int	组ID
// page	否	int	页码
// page_size	否	int	每页显示的条数（默认20）

export const getRoleList = (page, page_size = 10, group_id) => axios({
  method: 'get',
  url: exportURL(`${v}/${ugroup}/list`),
  params: {
    page,
    page_size
  }
});
// 组添加
// https://store.fdimall.com/v1/ugroup/add
// POST
// 参数名	必选	类型	说明
// group_name	是	string	组名称
// obj_ids	是	json	[1,2,3,4,5]
export const addRole = ({group_name, obj_ids}) => axios({
  method: 'post',
  url: exportURL(`${v}/${ugroup}/add`),
  data: {
    group_name,
    obj_ids
  }
});

// 组编辑
// https://store.fdimall.com/v1/ugroup/edit
// POST
// 参数名	必选	类型	说明
// group_id	是	int	组ID
// group_name	是	string	组名称
// obj_ids	是	json	[1,2,3,4,5,6]
export const editRole = data => axios({
  method: 'post',
  url: exportURL(`${v}/${ugroup}/edit`),
  data
});

// 禁用/启用 用户组
// https://store.fdimall.com/v1/ugroup/prohibit
// POST
// 参数名	必选	类型	说明
// group_id	是	int	用户组id
// is_true	是	int	1启用2禁用

export const isRoleEnabled = data => axios({
  method: 'post',
  url: exportURL(`${v}/${ugroup}/prohibit`),
  data
});

//  ----------------------------------------------------- roleList 角色列表


//  ***************************************************** jurisdictionList 权限列表
// 权限列表
// https://store.fdimall.com/v1/permission/list
// GET
// 参数：
// 参数名	必选	类型	说明
// permission_id	否	int	权限ID

export const getJurisdictionList = (page = 1, page_size = 20, permission_id) => axios({
  method: 'get',
  url: exportURL(`${v}/${permission}/list`),
  params: {
    page,
    page_size
  }
});


// 权限添加
// https://store.fdimall.com/v1/permission/add
// POST
// 参数名	必选	类型	说明
// title	是	string	权限名
// path	是	string	方法名
// is_show	是	int	是否显示 1显示2不显示
// is_true	是	int	是否启用 1启用2禁用

export const addJurisdiction = data => axios({
  method: 'post',
  url: exportURL(`${v}/${permission}/add`),
  data
});


// 权限编辑
// https://store.fdimall.com/v1/permission/edit
// POST
// 参数名	必选	类型	说明
// permission_id	是	int	权限ID
// title	是	string	权限名
// path	是	string	方法名
// is_show	是	int	是否显示 1显示2不显示
// is_true	是	int	是否启用 1启用2禁用
export const editJurisdiction = data => axios({
  method: 'post',
  url: exportURL(`${v}/${permission}/edit`),
  data
});
//  ----------------------------------------------------- jurisdictionList 权限列表


//  ***************************************************** supplierBefore 供应商订单列表
// 同财务的接口一样 直接调用财物的接口就好  后台根据token返回数据
// 获取订单详情 发货
// https://store.fdimall.com/v1/order/detail

export const getSupplierOrderDetails = (order_no, supplier_id) => axios({
  method: 'post',
  url: exportURL(`${v}/${order}/detail`),
  data: {
    order_no,
    supplier_id
  }
});

// 获取发货地址
// 收货地址id获取收货地址
// https://store.fdimall.com/v1/order/address
// GET
// receipt_address_id	是	string	收货地址id
export const getAddress = receipt_address_id => axios({
  url: exportURL(`${v}/${order}/address`),
  method: 'get',
  params: {
    receipt_address_id
  }
});


// 发货接口
// https://store.fdimall.com/v1/order/ship
export const deliverGoodsApi = data => axios({
  url: exportURL(`${v}/${order}/ship`),
  method: 'post',
  data
});

// 确认收货
// https://store.fdimall.com/v1/order/returnreview
// POST
// refund_no
export const confirmReceipt = refund_no => axios({
  url: exportURL(`${v}/${order}/returnreview`),
  method: 'post',
  data: {
    refund_no
  }
});

// 收货管理列表
// https://store.fdimall.com/v1/order/receiving
// GET
// page

export const receivingList = (page = 1) => axios({
  url: exportURL(`${v}/${order}/receiving`),
  method: 'get',
  params: {
    page
  }
});
//  ----------------------------------------------------- supplierBefore 供应商订单列表


// //  ***************************************************** supplierBefore 财物
// 获取订单列表
export const getSelfBeforeLsit = (page = 1) => axios({
  method: 'get',
  url: exportURL(`${v}/${order}/finance`),
  params: {
    page
  }
});
// 获取发票详情
export const getInvoiceInfo = (invoice_address_id, user_id, invoice_type) => axios({
  method: 'get',
  url: exportURL(`${v}/${order}/invoice`),
  params: {
    invoice_address_id,
    user_id,
    invoice_type
  }
});
// 获取订单详情
// v1/order/detail
// order_no
export const getOrderDetais = order_no => axios({
  method: 'get',
  url: exportURL(`${v}/${order}/financedetail`),
  params: {
    order_no
  }
});

// 获取收款单详情    暂时没用这个接口 直接用的下面的
export const getPaymentInfo = id => axios({
  method: 'get',
  url: exportURL(`${v}/${order}/`),  // 暂时还咩有接口 自己随便写的接口 后期换掉就好了
  params: {
    id
  }
});

// 收款单 触发数据...
export const postPaymentInfo = (id, digest) => axios({
  method: 'get',
  url: exportURL(`${v}/${order}/u8acceptadd`),
  params: {
    id,
    digest
  }
});


// 确认收款
// https://store.fdimall.com/v1/order/confirmedpaid
// POST
// order_no
export const confirmCollectMoney = order_no => axios({
  method: 'post',
  url: exportURL(`${v}/${order}/confirmedpaid`),
  data: {
    order_no
  }
});

// 财务确认退款
// https://store.fdimall.com/v1/order/confirmrefund
// POST
// refund_no
export const confirmrefund = refund_no => axios({
  method: 'post',
  url: exportURL(`${v}/${order}/confirmrefund`),
  data: {
    refund_no
  }
});

// 退款管理（财务）
// https://store.fdimall.com/v1/order/refund
// GET
// page	是	int	页号
export const getRefundLsit = (page = 1) => axios({
  method: 'get',
  url: exportURL(`${v}/${order}/refund`),
  params: {
    page
  }
});
// //  ----------------------------------------------------- supplierBefore 财物

// //  *****************************************************  客服
// https://store.fdimall.com/v1/order/checkrefund
// POST
// refund_no	是	string	退货单号

export const checkRefund = refund_no => axios({
  method: 'post',
  url: exportURL(`${v}/${order}/checkrefund`),
  data: {
    refund_no
  }
});

// 退货审核详情
// https://store.fdimall.com/v1/order/checkdetail
// GET
// refund_no
export const viewDetails = refund_no => axios({
  method: 'get',
  url: exportURL(`${v}/${order}/checkdetail`),
  params: {
    refund_no
  }
});


// 未支付订单库
// https://store.fdimall.com/v1/order/orderlibrary
// GET
export const getOrderlibrary = (page = 1, page_size = 10, search = '') => axios({
  method: 'get',
  url: exportURL(`${v}/${order}/orderlibrary`),
  params: {
    page,
    page_size,
    search
  }
});

// 订单修改
export const getOrderUnpaiDetais = (order_no, goods_price, freight_price) => {
  return axios({
    method: 'post',
    url: exportURL(`${v}/${order}/orderupdate`),
    data: {
      order_no,
      goods_price,
      freight_price
    }
  });
};


// //  -----------------------------------------------------  客服


// //  *****************************************************  历史采购价
// https://store.fdimall.com/v1/skp/materialsdemand
// params:invcode_stock, page_size=50, page=1
// get
// invcode_stock  是搜索项
export const getHistoryPurchasePrice = (page = 1, invcode_stock = '', page_size = 10) => axios({
  method: 'get',
  url: exportURL(`${v}/${skp}/materialsdemand`),
  params: {
    page,
    page_size,
    invcode_stock
  }
});
// //  -----------------------------------------------------  历史采购价
